/**
 * Copyright 2023 Inc.
 **/
package com.example.javaassist;

import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.security.ProtectionDomain;

/**
 * @author maoyz0621 on 2023/10/26
 * @version v1.0
 */
public class MyClassFileTransformer implements ClassFileTransformer {

    private String pkgName;

    public MyClassFileTransformer(String pkgName) {
        this.pkgName = pkgName.replace(".","/");
    }

    @Override
    public byte[] transform(ClassLoader loader,
                            String className,
                            Class<?> classBeingRedefined,
                            ProtectionDomain protectionDomain,
                            byte[] classfileBuffer) throws IllegalClassFormatException {
        // System.out.println("name="+className);
        if (className.startsWith(pkgName)){
            System.out.println("aaaaaaaaaaaaaaaaa");
        }
        return new byte[0];
    }
}